package org.arl.modem.transportARQ;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class CopyOfDrawTimeline2 {
   public static void main(String args[]) {
      try {
         FileInputStream fstream = new FileInputStream(
         // "/home/rohit/Desktop/arl/mod1/modem-sim/logs/log-0.txt");
               "/home/rohit/Desktop/pan3/rx5.txt");
         DataInputStream in = new DataInputStream(fstream);
         BufferedReader br = new BufferedReader(new InputStreamReader(in));
         FileWriter outFilestx = new FileWriter(
               "/home/rohit/Desktop/pan3a/stack21.txt");
         PrintWriter outstx = new PrintWriter(outFilestx);
         FileWriter outFilestx2 = new FileWriter(
               "/home/rohit/Desktop/pan3a/stack22.txt");
         PrintWriter outstx2 = new PrintWriter(outFilestx2);
         FileWriter outFilestx3 = new FileWriter(
               "/home/rohit/Desktop/pan3a/stack23.txt");
         PrintWriter outstx3 = new PrintWriter(outFilestx3);
         long l1 = 0;
         long prevl1 = 0;
         String strLine;
         long first = 0;
         int txc1 = 1;
         int rxc1 = 1;
         boolean fetchLink = false;
         boolean fetchTransport = false;
         long currentRxTime = 0;
         long currentRXPhytime = 0;
         long currentRXLinkTime = 0;
         long currentRxTspTime = 0;

         while ((strLine = br.readLine()) != null) {
            // Print the content on the console
            if (strLine.contains("~PRX.PKT.TIME=")) {
               // outstx.println(strLine);
               String s = strLine.split("~PRX.PKT.TIME=")[1].split(",")[0];
               String[] s3 = strLine.split("\\|");
               String s2 = s3[0];
               currentRxTime = Long.parseLong(s) / 1000;
               currentRXPhytime = Long.parseLong(s2) - currentRxTime;
               // outstx.println(currentRXPhytime);
               fetchLink = true;
            }
            if (strLine.contains("~LRX") && fetchLink) {
               // outstx.println(strLine);
               fetchLink = false;
               fetchTransport = true;
               currentRXLinkTime = Long.parseLong(strLine.split("\\|")[0])
                     - currentRxTime;
               // outstx2.println(currentRXLinkTime);
            }
            if (strLine.contains("~TRX") && fetchTransport) {
               // outstx.println(strLine);
               fetchTransport = false;
               currentRxTspTime = Long.parseLong(strLine.split("\\|")[0])
                     - currentRxTime;
               // outstx3.println(currentRxTspTime);
               outstx.println(currentRXPhytime + "," + currentRXLinkTime + ","
                     + currentRxTspTime);
            }
         }
         outstx.close();
         outstx2.close();
         outstx3.close();
         // outsrx.close();
         in.close();

      } catch (Exception e) {// Catch exception if any
         System.err.println("Error: " + e.getMessage());
      }
   }
}
